<!doctype html>
<html class="no-js">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>离线下载</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <meta name="msapplication-TileColor" content="#0e90d2">
    <link rel="stylesheet" href="https://cdn.bootcss.com/amazeui/2.7.2/css/amazeui.min.css">
</head>
<body>
<header class="am-topbar am-topbar-inverse">
    <div class="am-container am-cf">
        <div class="am-g">
            <h1 class="am-topbar-brand">
                <a href="#">离线下载</a>
            </h1>
            <!-- topbar-right -->
            <div class="am-topbar-right">
                <button class="am-btn am-btn-primary am-topbar-btn am-btn-sm">基于golang的下载神器</button>
            </div>
        </div>
    </div>

</header>

<div class="am-container">
    <div class="am-g">
        <div class="am-u-md-10 am-u-sm-centered">
            <legend>离线下载</legend>
            <div class="am-form-group">
                <p>欢迎使用！采用golang后台下载的方法实现简单的离线下载功能</p>
                <p>文件永久保留，下载空间为512M，若空间不足，请手工删除，且用且珍惜！</p>
                <div class="am-input-group">
						<span class="am-input-group-label">
							<i class="am-icon-cloud-download"></i>
						</span>
                    <input type="text" id="download" class="am-form-field" placeholder="请把文件的下载地址粘贴到这里,然后点击Enter即可。" />
                </div>
            </div>
            <button type="submit" class="am-btn am-btn-primary am-btn-block" onclick="download();">Enter</button>
        </div>
    </div>
    <div class="am-g">
        <div class="am-u-md-14 am-u-sm-centered">
            <table class="am-table am-table-hover">
                <thead>
                <tr>
                    <th>文件列表</th>
                </tr>
                </thead>
                <tbody id="downlist">

                </tbody>
            </table>
        </div>
    </div>
    <hr>

    <!-- 畅言 start -->
    <!--高速版-->
    <div id="SOHUCS" sid="请将此处替换为配置SourceID的语句"></div>
    <script charset="utf-8" type="text/javascript" src="http://changyan.sohu.com/upload/changyan.js" ></script>
    <script type="text/javascript">
        window.changyan.api.config({
            appid: 'cytKN5mQm',
            conf: 'prod_4c0c01fb0a12851abbece0036fd6b110'
        });
    </script>
    <!-- 畅言 end -->

</div>
<footer ata-am-widget="footer" class="am-footer am-footer-default" style="
    background:#555;
	font-color:#000;
">
    <style>
        .am-footer-default a{
            color:#999;
        }
    </style>
    <div class="am-footer-miscs">
        <p></p>
    </div>
</footer>

<div class="am-modal am-modal-no-btn" tabindex="-1" id="downerror">
    <div class="am-modal-dialog">
        <div class="am-modal-hd">错误
            <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
        </div>
        <div class="am-modal-bd">
            下载出现错误，可能是不允许的文件后缀或下载空间已满。
        </div>
    </div>
</div>

<!--[if lt IE 9]>
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script src="//cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="/js/polyfill/rem.min.js"></script>
<script src="http://libs.baidu.com/respond.js/1.4.2/respond.min.js"></script>
<script src="https://cdn.bootcss.com/amazeui/2.4.0/js/amazeui.legacy.min.js"></script>
<![endif]-->

<!--[if (gte IE 9)|!(IE)]><!-->
<script src="http://libs.baidu.com/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/amazeui/2.7.2/css/amazeui.min.css"></script>
<!--<![endif]-->
<script>
    function writeDownList() {
        $.getJSON('./downlist',null,function (data) {
            var downlist = document.getElementById('downlist');
            downlist.innerHTML = '<tr><td>#</td><td>名称</td><td>修改时间</td><td>大小</td><td>操作</td></tr>';
            for (var i = 0 ; i < data.length ; i++) {
                downlist.innerHTML = downlist.innerHTML + '<tr><td>' + i + '</td><td><a href="./download/' + data[i]['name'] + '">' + data[i]['name'] + '</a></td><td>' + data[i]['mtime'] + '</td><td>' + data[i]['size'] + '</td><td><button type="button" class="am-btn" onclick="del(\'' + data[i]['name'] + '\');">删除</button></td></tr>';
            }
        });
    }
    function download() {
        var url = document.getElementById("download").value;
        $.get('./down',{'url':url},function (data) {
            if (data == 'success') {
                writeDownList();
            } else {
                $('#downerror').modal();
            }
        });
    }
    function del(file) {
        $.get('./delete',{'file':file},function (data) {
            writeDownList();
        });
    }
    writeDownList();
</script>
</body>
</html>
